package leetcode_day._2021._202105._2131;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/21 21:51
 * 不相交的线
 * 算法：数组  动态规划（最长公共子序列）
 */
public class _21_1035 {

    public int maxUncrossedLines(int[] nums1, int[] nums2) {
        int m = nums1.length, n = nums2.length;
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++) {
                dp[i][j] = dp[i - 1][j] > dp[i][j - 1] ? dp[i - 1][j] : dp[i][j - 1];
                if (nums1[i - 1] == nums2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        return dp[m][n];
    }
}
